package com.utm.gameoka;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class SolicitudAdapter extends BaseAdapter {

	private Activity activity;
	private List<SolicitudModel> data;
	private static LayoutInflater inflater = null;

	public SolicitudAdapter(Activity actividad, List<SolicitudModel> lista) {
		activity = actividad;
		data = lista;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		return data.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.solicitud_row_componente, null);

		TextView username_partida = (TextView) vi.findViewById(R.id.lblSolicitudUsuario); // usuario
		TextView partida = (TextView) vi.findViewById(R.id.lblSolicitudPartida); // usuario		
		Button btnConfirmar = (Button) vi.findViewById(R.id.btnSolicitudConfirmar); //
		Button btnRechazar = (Button) vi.findViewById(R.id.btnSolicitudRechazar); // 
		// ImageView thumb_image=(ImageView)vi.findViewById(R.id.listImage);

		username_partida.setText(data.get(position).getUsuarioPartida());
		partida.setText(data.get(position).getFecha());
		// imageLoader.DisplayImage(l, thumb_image);
		final int pos = position;
		final String iPartida = data.get(position).getIdPartida();
		btnConfirmar.setOnClickListener(new OnClickListener() {
			public void onClick(View v){
				data.get(pos).setIdPartida(iPartida);
				((MainActivity)activity).aceptaSolicitud(iPartida);
			}
		});

		return vi;
	}

}
